package com.qf.smartplatform.controller;

import com.qf.smartplatform.dto.R;
import com.qf.smartplatform.pojo.SysRole;
import com.qf.smartplatform.service.RoleService;
import com.qf.smartplatform.valigroup.delete;
import com.qf.smartplatform.valigroup.insert;
import com.qf.smartplatform.valigroup.select;
import com.qf.smartplatform.valigroup.update;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*** @author Tgb
 * @version V1.0
 * @Project smartplatform
 * @Package com.qf.smartplatform.controller
 * @Description:
 * @Date 2022/9/12 21:22
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    private RoleService roleService;
    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping("/add")
    public R addRole(@Validated(insert.class)@RequestBody SysRole sysRole){

        roleService.addRole(sysRole);
        return R.OK();
    }
    @PostMapping("/select")
    public R findById(@Validated(select.class) @Param("roleId") Long roleId){
        return R.OK(roleService.findById(roleId));
    }
    @PostMapping("/selectAll")
    public R findAll(){
        return R.OK(roleService.findAll());
    }
    @PostMapping("/delete")
    public R deleteById(@Validated(delete.class) @Param("roleId")Long roleId){
        roleService.deleteById(roleId);
        return R.OK();
    }
    @PostMapping("/update")
    public R updateRole(@Validated(update.class)@RequestBody SysRole sysRole){
        roleService.updateRole(sysRole);
        return R.OK();
    }
}
